package com.artisan.boottraditionaldesign.controller;


import com.artisan.boottraditionaldesign.factory.MessageServiceFactory;
import com.artisan.boottraditionaldesign.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TraditionalMessageController {

    private final MessageServiceFactory messageServiceFactory;

    @Autowired
    public TraditionalMessageController(MessageServiceFactory messageServiceFactory) {
        this.messageServiceFactory = messageServiceFactory;
    }

    @GetMapping("/sendMessage")
    public String sendMessage(@RequestParam String type, @RequestParam String message) {
        MessageService service = messageServiceFactory.createService(type);
        service.sendMessage(message);
        return "Message sent using " + type + " service!";
    }
}
